package com.oauth.twitter.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.oauth.components.client.ui.gadgets.ProfileInfoPanel;
import com.oauth.twitter.client.beans.TwitterModel;
import com.oauth.twitter.client.beans.TwitterUser;
import com.oauth.twitter.client.rpc.TwitterRemoteServiceAsync;
import com.oauth.twitter.client.ui.handler.StatusUpdateHandler;

public class HomePanel extends Composite {

	private static HomePanelUiBinder uiBinder = GWT.create(HomePanelUiBinder.class);

	interface HomePanelUiBinder extends UiBinder<Widget, HomePanel> {
	}

	@UiField
	HorizontalPanel hPanel1;

	@UiField
	ProfileInfoPanel infoPanel;

	@UiField
	Image twitterImage;

	@UiField
	TweetsPanel tweetsPanel;

	private TwitterRemoteServiceAsync mService;

	public HomePanel() {
		initWidget(uiBinder.createAndBindUi(this));
		hPanel1.setCellHorizontalAlignment(infoPanel, VerticalPanel.ALIGN_LEFT);
		hPanel1.setCellHorizontalAlignment(twitterImage, VerticalPanel.ALIGN_RIGHT);
	}

	public void setData(TwitterModel pTwitterModel) {
		infoPanel.addValueChangeHandler(new StatusUpdateHandler(mService, tweetsPanel));
		TwitterUser user = pTwitterModel.getUser();
		infoPanel.setData(user.getProfileImageUrl(), user.getName(), user.getStatus());
		tweetsPanel.addTweet(pTwitterModel.getTweets());
	}

	public void setService(TwitterRemoteServiceAsync pTwitterService) {
		mService = pTwitterService;
	}

}
